<?php
class mapController extends baseController{
    public function index(){
        $tags = array();
         if(isset($_POST['place'])){
             $tags = array(
                 "place"    =>$_POST['place'],
                 "lat"      => "null",
                 "lng"      => "null"
             );
             $this->master( $this->registry->template->getTemplate("radius", $tags));
         }else if(isset($_POST['lat']) & isset($_POST['lng']) ){
             $tags = array(
                 "place"    =>"",
                 "lat"      =>$_POST['lat'],
                 "lng"      =>$_POST['lng']
             );
             $this->master( $this->registry->template->getTemplate("radius", $tags));
         }else{
             $tags = array(
                 "place"    =>"",
                 "lat"      =>"null",
                 "lng"      =>"null"
             );
             $this->master( $this->registry->template->getTemplate("radius", $tags));
         }

//        $this->master( $this->registry->template->getTemplate("radius", $tags));
    }

    public function radius(){
        if(isset($_GET['para'])){
            $para = $_GET['para'];
            $para = explode(",",$para);
            $lat = substr($para[0],1);
            $lng = substr($para[1], 1, strlen($para[1]-1) );
            $d = $_GET['d'];

            $data = $this->registry->db->getManager("mapManager")->radius(deg2rad($lat), deg2rad($lng), $d);
            $tags = array(
                "user"        => "",
                "header"      => $this->registry->template->getTemplate("header", array()),
                "mmenu"       => $this->registry->template->getTemplate("mmenu", array()),
//                "data"          => $data,
//                "radius"          => $d,
//                "infowindows"   => "",//$this->registry->template->getTemplate("infowindows", array()),
//                "temp"          => $d
            );
            echo $this->registry->template->getTemplate("radius2", $tags);
        }
        else{
            echo $this->registry->template->getTemplate("index", array());
            $this->master($this->registry->template->index());
        }


    }

    public function getplace(){
        $c = mysql_real_escape_string($_GET['c']);
        $c = explode(",",$c);
        $lat = substr($c[0],1);
        $lng = substr($c[1], 1, strlen($c[1]-1) );
        $d = mysql_real_escape_string($_GET['d']);

        echo $data = $this->registry->db->getManager("mapManager")->radius(deg2rad($lat), deg2rad($lng), $d);
    }
}
?>